<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <table border="1">
        <caption>员工列表</caption>
        <tr>
            <th>id</th><th>姓名</th><th>工资</th><th>工作</th><th>操作</th>
        </tr>
        <tr v-for="emp in arr">
            <td>{{emp.id}}</td>
            <th>{{emp.name}}</th>
            <td>{{emp.sal}}</td>
            <td>{{emp.job}}</td>
            <!--javascript:void(0)废掉超链接自带的跳转功能-->
            <td>
                <a :href="'/update.html?id='+emp.id">修改</a>
                <a href="javascript:void(0)" @click="del(emp.id)">删除</a>
            </td>
        </tr>
    </table>
</div>

<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<script>
    let v = new Vue({
        el:"body>div",
        data:{
            arr:[]
        },
        methods:{
            del(id){
                if (confirm("您确认删除此员工吗?")){
                    //发出异步的删除请求
                    axios.get("/delete?id="+id).then(function (response) {
                        //删除完成后  页面重新刷新
                        location.reload();
                    })
                }

            }
        },
        //created方法是Vue对象中提供的方法,会在创建Vue对象时自动调用,通常进入页面发请求的代码写在这里
        created:function () {
            //发出异步get请求获取数据
            axios.get("/select").then(function (response) {
                v.arr=response.data;
            })
        }
    })
</script>
</body>
</html>